﻿class Ship extends MovieClip
{
	var velocity;
	var shootLimiter;
	var enemyTimer;
	var frameRate;
	function onLoad()
	{
		velocity = 10;
		shootLimiter = 0;
		enemyTimer = 0;
		frameRate = 1;
	}
	function onEnterFrame()
	{
		shootLimiter += 1;
		if(Key.isDown(Key.RIGHT))
		{
			_x = _x + velocity;
		}
		if( Key.isDown(Key.LEFT) )
		{
			_x = _x - velocity;
		}
		if( Key.isDown(Key.UP) )
		{
			_y = _y - velocity;
		}
		if( Key.isDown(Key.DOWN) )
		{
			_y = _y + velocity;
		}
		if( Key.isDown(Key.SPACE) && shootLimiter > 7)
		{
			shootLimiter = 0;
			var missile = _root.attachMovie( "Missile" , "Missile" + _root.getNextHighestDepth(), _root.getNextHighestDepth() );
			missile._x = _x + 80 ;
			missile._y = _y + 19 ;
		}
		
		//Enemy Timer
		enemyTimer += frameRate;
		if(enemyTimer > 30)
		{
				enemyTimer = 0;
				_root.attachMovie("EnemyShip", "EnemyShip" +_root.getNextHighestDepth(), _root.getNextHighestDepth());
				frameRate = Math.random()*3 + 1;
		}
	}
}